package com.toshi.netlib.interceptors;

import com.toshi.netlib.base.INetworkRequiredInfo;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;


/**
 * 公共的请求拦截器  用于添加head相关信息
 */
public class CommonRequestInterceptor implements Interceptor {

    private INetworkRequiredInfo networkRequiredInfo;

    public CommonRequestInterceptor(INetworkRequiredInfo networkRequiredInfo) {
        this.networkRequiredInfo = networkRequiredInfo;
    }


    @Override
    public Response intercept(Chain chain) throws IOException {
//        Request.Builder builder = new Request.Builder();
        Request.Builder builder = chain.request().newBuilder();
        builder.addHeader("os", "android");
        builder.addHeader("appVersion", networkRequiredInfo.getAppVersionCode());
        return chain.proceed(builder.build());
    }
}
